{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "ename": "ProxyError",
     "evalue": "HTTPSConnectionPool(host='voice.baidu.com', port=443): Max retries exceeded with url: /act/newpneumonia/newpneumonia (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mRemoteDisconnected\u001b[0m                        Traceback (most recent call last)",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python38\\site-packages\\urllib3\\connectionpool.py:667\u001b[0m, in \u001b[0;36mHTTPConnectionPool.urlopen\u001b[1;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/urllib3/connectionpool.py?line=665'>666</a>\u001b[0m \u001b[39mif\u001b[39;00m is_new_proxy_conn:\n\u001b[1;32m--> <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/urllib3/connectionpool.py?line=666'>667</a>\u001b[0m     \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_prepare_proxy(conn)\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/urllib3/connectionpool.py?line=668'>669</a>\u001b[0m \u001b[39m# Make the request on the httplib connection object.\u001b[39;00m\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python38\\site-packages\\urllib3\\connectionpool.py:932\u001b[0m, in \u001b[0;36mHTTPSConnectionPool._prepare_proxy\u001b[1;34m(self, conn)\u001b[0m\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/urllib3/connectionpool.py?line=930'>931</a>\u001b[0m conn\u001b[39m.\u001b[39mset_tunnel(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_proxy_host, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mport, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mproxy_headers)\n\u001b[1;32m--> <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/urllib3/connectionpool.py?line=931'>932</a>\u001b[0m conn\u001b[39m.\u001b[39;49mconnect()\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python38\\site-packages\\urllib3\\connection.py:317\u001b[0m, in \u001b[0;36mHTTPSConnection.connect\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/urllib3/connection.py?line=314'>315</a>\u001b[0m \u001b[39m# Calls self._set_hostport(), so self.host is\u001b[39;00m\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/urllib3/connection.py?line=315'>316</a>\u001b[0m \u001b[39m# self._tunnel_host below.\u001b[39;00m\n\u001b[1;32m--> <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/urllib3/connection.py?line=316'>317</a>\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_tunnel()\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/urllib3/connection.py?line=317'>318</a>\u001b[0m \u001b[39m# Mark this connection as not reusable\u001b[39;00m\n",
      "File \u001b[1;32mC:\\Program Files\\Python38\\lib\\http\\client.py:894\u001b[0m, in \u001b[0;36mHTTPConnection._tunnel\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    <a href='file:///c%3A/Program%20Files/Python38/lib/http/client.py?line=892'>893</a>\u001b[0m response \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mresponse_class(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39msock, method\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_method)\n\u001b[1;32m--> <a href='file:///c%3A/Program%20Files/Python38/lib/http/client.py?line=893'>894</a>\u001b[0m (version, code, message) \u001b[39m=\u001b[39m response\u001b[39m.\u001b[39;49m_read_status()\n\u001b[0;32m    <a href='file:///c%3A/Program%20Files/Python38/lib/http/client.py?line=895'>896</a>\u001b[0m \u001b[39mif\u001b[39;00m code \u001b[39m!=\u001b[39m http\u001b[39m.\u001b[39mHTTPStatus\u001b[39m.\u001b[39mOK:\n",
      "File \u001b[1;32mC:\\Program Files\\Python38\\lib\\http\\client.py:272\u001b[0m, in \u001b[0;36mHTTPResponse._read_status\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    <a href='file:///c%3A/Program%20Files/Python38/lib/http/client.py?line=268'>269</a>\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m line:\n\u001b[0;32m    <a href='file:///c%3A/Program%20Files/Python38/lib/http/client.py?line=269'>270</a>\u001b[0m     \u001b[39m# Presumably, the server closed the connection before\u001b[39;00m\n\u001b[0;32m    <a href='file:///c%3A/Program%20Files/Python38/lib/http/client.py?line=270'>271</a>\u001b[0m     \u001b[39m# sending a valid response.\u001b[39;00m\n\u001b[1;32m--> <a href='file:///c%3A/Program%20Files/Python38/lib/http/client.py?line=271'>272</a>\u001b[0m     \u001b[39mraise\u001b[39;00m RemoteDisconnected(\u001b[39m\"\u001b[39m\u001b[39mRemote end closed connection without\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m    <a href='file:///c%3A/Program%20Files/Python38/lib/http/client.py?line=272'>273</a>\u001b[0m                              \u001b[39m\"\u001b[39m\u001b[39m response\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m    <a href='file:///c%3A/Program%20Files/Python38/lib/http/client.py?line=273'>274</a>\u001b[0m \u001b[39mtry\u001b[39;00m:\n",
      "\u001b[1;31mRemoteDisconnected\u001b[0m: Remote end closed connection without response",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mMaxRetryError\u001b[0m                             Traceback (most recent call last)",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python38\\site-packages\\requests\\adapters.py:439\u001b[0m, in \u001b[0;36mHTTPAdapter.send\u001b[1;34m(self, request, stream, timeout, verify, cert, proxies)\u001b[0m\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=437'>438</a>\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m chunked:\n\u001b[1;32m--> <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=438'>439</a>\u001b[0m     resp \u001b[39m=\u001b[39m conn\u001b[39m.\u001b[39;49murlopen(\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=439'>440</a>\u001b[0m         method\u001b[39m=\u001b[39;49mrequest\u001b[39m.\u001b[39;49mmethod,\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=440'>441</a>\u001b[0m         url\u001b[39m=\u001b[39;49murl,\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=441'>442</a>\u001b[0m         body\u001b[39m=\u001b[39;49mrequest\u001b[39m.\u001b[39;49mbody,\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=442'>443</a>\u001b[0m         headers\u001b[39m=\u001b[39;49mrequest\u001b[39m.\u001b[39;49mheaders,\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=443'>444</a>\u001b[0m         redirect\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=444'>445</a>\u001b[0m         assert_same_host\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=445'>446</a>\u001b[0m         preload_content\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=446'>447</a>\u001b[0m         decode_content\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=447'>448</a>\u001b[0m         retries\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mmax_retries,\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=448'>449</a>\u001b[0m         timeout\u001b[39m=\u001b[39;49mtimeout\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=449'>450</a>\u001b[0m     )\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=451'>452</a>\u001b[0m \u001b[39m# Send the request.\u001b[39;00m\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=452'>453</a>\u001b[0m \u001b[39melse\u001b[39;00m:\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python38\\site-packages\\urllib3\\connectionpool.py:726\u001b[0m, in \u001b[0;36mHTTPConnectionPool.urlopen\u001b[1;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/urllib3/connectionpool.py?line=723'>724</a>\u001b[0m     e \u001b[39m=\u001b[39m ProtocolError(\u001b[39m\"\u001b[39m\u001b[39mConnection aborted.\u001b[39m\u001b[39m\"\u001b[39m, e)\n\u001b[1;32m--> <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/urllib3/connectionpool.py?line=725'>726</a>\u001b[0m retries \u001b[39m=\u001b[39m retries\u001b[39m.\u001b[39;49mincrement(\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/urllib3/connectionpool.py?line=726'>727</a>\u001b[0m     method, url, error\u001b[39m=\u001b[39;49me, _pool\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m, _stacktrace\u001b[39m=\u001b[39;49msys\u001b[39m.\u001b[39;49mexc_info()[\u001b[39m2\u001b[39;49m]\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/urllib3/connectionpool.py?line=727'>728</a>\u001b[0m )\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/urllib3/connectionpool.py?line=728'>729</a>\u001b[0m retries\u001b[39m.\u001b[39msleep()\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python38\\site-packages\\urllib3\\util\\retry.py:446\u001b[0m, in \u001b[0;36mRetry.increment\u001b[1;34m(self, method, url, response, error, _pool, _stacktrace)\u001b[0m\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/urllib3/util/retry.py?line=444'>445</a>\u001b[0m \u001b[39mif\u001b[39;00m new_retry\u001b[39m.\u001b[39mis_exhausted():\n\u001b[1;32m--> <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/urllib3/util/retry.py?line=445'>446</a>\u001b[0m     \u001b[39mraise\u001b[39;00m MaxRetryError(_pool, url, error \u001b[39mor\u001b[39;00m ResponseError(cause))\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/urllib3/util/retry.py?line=447'>448</a>\u001b[0m log\u001b[39m.\u001b[39mdebug(\u001b[39m\"\u001b[39m\u001b[39mIncremented Retry for (url=\u001b[39m\u001b[39m'\u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m'\u001b[39m\u001b[39m): \u001b[39m\u001b[39m%r\u001b[39;00m\u001b[39m\"\u001b[39m, url, new_retry)\n",
      "\u001b[1;31mMaxRetryError\u001b[0m: HTTPSConnectionPool(host='voice.baidu.com', port=443): Max retries exceeded with url: /act/newpneumonia/newpneumonia (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mProxyError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32mc:\\Users\\86183\\Desktop\\public_ sentiment\\Corona-visual\\baidu.ipynb Cell 1'\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      <a href='vscode-notebook-cell:/c%3A/Users/86183/Desktop/public_%20sentiment/Corona-visual/baidu.ipynb#ch0000000?line=6'>7</a>\u001b[0m url \u001b[39m=\u001b[39m \u001b[39m'\u001b[39m\u001b[39mhttps://voice.baidu.com/act/newpneumonia/newpneumonia\u001b[39m\u001b[39m'\u001b[39m\n\u001b[0;32m      <a href='vscode-notebook-cell:/c%3A/Users/86183/Desktop/public_%20sentiment/Corona-visual/baidu.ipynb#ch0000000?line=7'>8</a>\u001b[0m headers \u001b[39m=\u001b[39m {\n\u001b[0;32m      <a href='vscode-notebook-cell:/c%3A/Users/86183/Desktop/public_%20sentiment/Corona-visual/baidu.ipynb#ch0000000?line=8'>9</a>\u001b[0m     \u001b[39m'\u001b[39m\u001b[39mUser-Agent\u001b[39m\u001b[39m'\u001b[39m: \u001b[39m'\u001b[39m\u001b[39mMozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36\u001b[39m\u001b[39m'\u001b[39m}\n\u001b[1;32m---> <a href='vscode-notebook-cell:/c%3A/Users/86183/Desktop/public_%20sentiment/Corona-visual/baidu.ipynb#ch0000000?line=9'>10</a>\u001b[0m response \u001b[39m=\u001b[39m requests\u001b[39m.\u001b[39;49mget(url\u001b[39m=\u001b[39;49murl, headers\u001b[39m=\u001b[39;49mheaders)\u001b[39m.\u001b[39mtext\n\u001b[0;32m     <a href='vscode-notebook-cell:/c%3A/Users/86183/Desktop/public_%20sentiment/Corona-visual/baidu.ipynb#ch0000000?line=11'>12</a>\u001b[0m html \u001b[39m=\u001b[39m etree\u001b[39m.\u001b[39mHTML(response)\n\u001b[0;32m     <a href='vscode-notebook-cell:/c%3A/Users/86183/Desktop/public_%20sentiment/Corona-visual/baidu.ipynb#ch0000000?line=13'>14</a>\u001b[0m json_text \u001b[39m=\u001b[39m html\u001b[39m.\u001b[39mxpath(\u001b[39m'\u001b[39m\u001b[39m//script[@type=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mapplication/json\u001b[39m\u001b[39m\"\u001b[39m\u001b[39m]/text()\u001b[39m\u001b[39m'\u001b[39m)\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python38\\site-packages\\requests\\api.py:76\u001b[0m, in \u001b[0;36mget\u001b[1;34m(url, params, **kwargs)\u001b[0m\n\u001b[0;32m     <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/api.py?line=64'>65</a>\u001b[0m \u001b[39mr\u001b[39m\u001b[39m\"\"\"Sends a GET request.\u001b[39;00m\n\u001b[0;32m     <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/api.py?line=65'>66</a>\u001b[0m \n\u001b[0;32m     <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/api.py?line=66'>67</a>\u001b[0m \u001b[39m:param url: URL for the new :class:`Request` object.\u001b[39;00m\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m     <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/api.py?line=71'>72</a>\u001b[0m \u001b[39m:rtype: requests.Response\u001b[39;00m\n\u001b[0;32m     <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/api.py?line=72'>73</a>\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[0;32m     <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/api.py?line=74'>75</a>\u001b[0m kwargs\u001b[39m.\u001b[39msetdefault(\u001b[39m'\u001b[39m\u001b[39mallow_redirects\u001b[39m\u001b[39m'\u001b[39m, \u001b[39mTrue\u001b[39;00m)\n\u001b[1;32m---> <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/api.py?line=75'>76</a>\u001b[0m \u001b[39mreturn\u001b[39;00m request(\u001b[39m'\u001b[39;49m\u001b[39mget\u001b[39;49m\u001b[39m'\u001b[39;49m, url, params\u001b[39m=\u001b[39;49mparams, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python38\\site-packages\\requests\\api.py:61\u001b[0m, in \u001b[0;36mrequest\u001b[1;34m(method, url, **kwargs)\u001b[0m\n\u001b[0;32m     <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/api.py?line=56'>57</a>\u001b[0m \u001b[39m# By using the 'with' statement we are sure the session is closed, thus we\u001b[39;00m\n\u001b[0;32m     <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/api.py?line=57'>58</a>\u001b[0m \u001b[39m# avoid leaving sockets open which can trigger a ResourceWarning in some\u001b[39;00m\n\u001b[0;32m     <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/api.py?line=58'>59</a>\u001b[0m \u001b[39m# cases, and look like a memory leak in others.\u001b[39;00m\n\u001b[0;32m     <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/api.py?line=59'>60</a>\u001b[0m \u001b[39mwith\u001b[39;00m sessions\u001b[39m.\u001b[39mSession() \u001b[39mas\u001b[39;00m session:\n\u001b[1;32m---> <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/api.py?line=60'>61</a>\u001b[0m     \u001b[39mreturn\u001b[39;00m session\u001b[39m.\u001b[39;49mrequest(method\u001b[39m=\u001b[39;49mmethod, url\u001b[39m=\u001b[39;49murl, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python38\\site-packages\\requests\\sessions.py:530\u001b[0m, in \u001b[0;36mSession.request\u001b[1;34m(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)\u001b[0m\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/sessions.py?line=524'>525</a>\u001b[0m send_kwargs \u001b[39m=\u001b[39m {\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/sessions.py?line=525'>526</a>\u001b[0m     \u001b[39m'\u001b[39m\u001b[39mtimeout\u001b[39m\u001b[39m'\u001b[39m: timeout,\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/sessions.py?line=526'>527</a>\u001b[0m     \u001b[39m'\u001b[39m\u001b[39mallow_redirects\u001b[39m\u001b[39m'\u001b[39m: allow_redirects,\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/sessions.py?line=527'>528</a>\u001b[0m }\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/sessions.py?line=528'>529</a>\u001b[0m send_kwargs\u001b[39m.\u001b[39mupdate(settings)\n\u001b[1;32m--> <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/sessions.py?line=529'>530</a>\u001b[0m resp \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49msend(prep, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49msend_kwargs)\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/sessions.py?line=531'>532</a>\u001b[0m \u001b[39mreturn\u001b[39;00m resp\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python38\\site-packages\\requests\\sessions.py:643\u001b[0m, in \u001b[0;36mSession.send\u001b[1;34m(self, request, **kwargs)\u001b[0m\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/sessions.py?line=639'>640</a>\u001b[0m start \u001b[39m=\u001b[39m preferred_clock()\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/sessions.py?line=641'>642</a>\u001b[0m \u001b[39m# Send the request\u001b[39;00m\n\u001b[1;32m--> <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/sessions.py?line=642'>643</a>\u001b[0m r \u001b[39m=\u001b[39m adapter\u001b[39m.\u001b[39;49msend(request, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/sessions.py?line=644'>645</a>\u001b[0m \u001b[39m# Total elapsed time of the request (approximately)\u001b[39;00m\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/sessions.py?line=645'>646</a>\u001b[0m elapsed \u001b[39m=\u001b[39m preferred_clock() \u001b[39m-\u001b[39m start\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python38\\site-packages\\requests\\adapters.py:510\u001b[0m, in \u001b[0;36mHTTPAdapter.send\u001b[1;34m(self, request, stream, timeout, verify, cert, proxies)\u001b[0m\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=506'>507</a>\u001b[0m     \u001b[39mraise\u001b[39;00m RetryError(e, request\u001b[39m=\u001b[39mrequest)\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=508'>509</a>\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(e\u001b[39m.\u001b[39mreason, _ProxyError):\n\u001b[1;32m--> <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=509'>510</a>\u001b[0m     \u001b[39mraise\u001b[39;00m ProxyError(e, request\u001b[39m=\u001b[39mrequest)\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=511'>512</a>\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(e\u001b[39m.\u001b[39mreason, _SSLError):\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=512'>513</a>\u001b[0m     \u001b[39m# This branch is for urllib3 v1.22 and later.\u001b[39;00m\n\u001b[0;32m    <a href='file:///c%3A/Users/86183/AppData/Roaming/Python/Python38/site-packages/requests/adapters.py?line=513'>514</a>\u001b[0m     \u001b[39mraise\u001b[39;00m SSLError(e, request\u001b[39m=\u001b[39mrequest)\n",
      "\u001b[1;31mProxyError\u001b[0m: HTTPSConnectionPool(host='voice.baidu.com', port=443): Max retries exceeded with url: /act/newpneumonia/newpneumonia (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "from lxml import etree\n",
    "import json\n",
    "import openpyxl\n",
    "\n",
    "\n",
    "url = 'https://voice.baidu.com/act/newpneumonia/newpneumonia'\n",
    "headers = {\n",
    "    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'}\n",
    "response = requests.get(url=url, headers=headers).text\n",
    "\n",
    "html = etree.HTML(response)\n",
    "\n",
    "json_text = html.xpath('//script[@type=\"application/json\"]/text()')\n",
    "\n",
    "json_text = json_text[0]\n",
    "\n",
    "b = json.dumps(json_text)\n",
    "f2 = open('new_json.json', 'w')\n",
    "f2.write(b)\n",
    "f2.close()\n",
    "\n",
    "# result = json.loads(json_text)\n",
    "# print(result)\n",
    "# result = result[\"component\"]\n",
    "# result = result[0]['caseList']\n",
    "\n",
    "'''\n",
    "wb = openpyxl.Workbook()\n",
    "ws = wb.active\n",
    "ws.title = \"国内疫情\"\n",
    "ws.append([\"省份\", \"确诊\", \"死亡\", \"治愈\"])\n",
    "\n",
    "\n",
    "for line in result:\n",
    "    line_name = [line[\"area\"], line[\"confirmed\"], line[\"died\"], line[\"crued\"]]\n",
    "    for ele in line_name:\n",
    "        if ele == '':\n",
    "            ele = 0\n",
    "    ws.append(line_name)\n",
    "\n",
    "    # print(line_name)\n",
    "\n",
    "wb.save('C:/Users/86183/Desktop/china.xlsx')\n",
    "\n",
    "#可视化\n",
    "import pandas as pd\n",
    "from pyecharts.charts import Map,Page\n",
    "from pyecharts import options as opts\n",
    "\n",
    "pd.set_option('display.unicode.ambiguous_as_wide', True)\n",
    "pd.set_option('display.unicode.east_asian_width', True)\n",
    "\n",
    "df = pd.read_excel('C:/Users/86183/Desktop/china.xlsx')\n",
    "\n",
    "data2 = df['省份']\n",
    "data2_list = list(data2)\n",
    "data3 = df['确诊']\n",
    "data3_list = list(data3)\n",
    "data4 = df['死亡']\n",
    "data4_list = list(data4)\n",
    "data5 = df ['治愈']\n",
    "data5_list = list(data5)\n",
    "\n",
    "c = (\n",
    "    Map()\n",
    "    .add(\"确诊\", [list(z) for z in zip(data2_list, data5_list)], \"china\")\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(),\n",
    "        visualmap_opts=opts.VisualMapOpts(max_=200),\n",
    "                    )\n",
    "    )\n",
    "\n",
    "c.render()\n",
    "'''\n"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "1baa965d5efe3ac65b79dfc60c0d706280b1da80fedb7760faf2759126c4f253"
  },
  "kernelspec": {
   "display_name": "Python 3.8.2 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
